#include <stdio.h>

int main()
{
    int N;
    scanf("%d", &N);

    int numbers[10];

    for (int i = 0; i < N; ++i)
    {
        scanf("%d", &numbers[i]);
    }

    int minIndex = 0, maxIndex = 0;
    for (int i = 1; i < N; ++i)
    {
        if (numbers[i] < numbers[minIndex])
        {
            minIndex = i;
        }
        if (numbers[i] > numbers[maxIndex])
        {
            maxIndex = i;
        }
    }

    int temp = numbers[0];
    numbers[0] = numbers[minIndex];
    numbers[minIndex] = temp;
    if(maxIndex == 0) maxIndex = minIndex;
    temp = numbers[N - 1];
    numbers[N - 1] = numbers[maxIndex];
    numbers[maxIndex] = temp;
    for (int i = 0; i < N; ++i)
    {
        printf("%d ", numbers[i]);
    }
    printf("\n");

    return 0;
}
